package org.apache.httpclient;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class Test
{

    public static void main(String[] args) throws ClientProtocolException, IOException
    {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://www.baidu.com");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null)
        {
            
            try(InputStream  instream = entity.getContent() ){
                byte[]data =new byte[1024];
                int i = 0;
                while((i = instream.read(data))!=-1){
                    System.out.println(new String(data,0,i));
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
            
        }
    }
}
